﻿Imports MonolithHelper
Public Class jfClientLogic

#Region "Configurations"
    Private _ScrnPrntInterval As Integer
    Public Property ScrnPrntInterval() As Integer
        Get
            Return _ScrnPrntInterval
        End Get
        Set(ByVal value As Integer)
            _ScrnPrntInterval = value
        End Set
    End Property


    Private _currentPrntTime As DateTime
    Public Property currentPrntTime() As DateTime
        Get
            Return _currentPrntTime
        End Get
        Set(ByVal value As DateTime)
            _currentPrntTime = value
        End Set
    End Property


    Private _currentFileCreatedOn As DateTime
    Public Property currentFileCreatedOn() As DateTime
        Get
            Return _currentFileCreatedOn
        End Get
        Set(ByVal value As DateTime)
            _currentFileCreatedOn = value
        End Set
    End Property


#End Region


    Public Shared Function WriteLog(ByVal message As String, ByVal title As String) As String
        Logger.Write(message, title)
        Return message
    End Function
   
    Public Shared Function IsLoggedOn() As String

        Dim res As String = String.Empty


        Try

            Dim TimReports = From p In System.Diagnostics.Process.GetProcessesByName("TimeReport") _
                           Select p.Handle

            If TimReports.Count > 0 Then

                MonolithHelper.ColorPhone.LoadDataFromXML(My.MySettings.Default.ColorPhoneXmlPath)

                res = ColorPhone.strUserID


            Else
                Dim Colorphone = From p In System.Diagnostics.Process.GetProcessesByName("ColorPhone") _
                          Select p.Handle

                If Colorphone.Count > 1 Then
                    MonolithHelper.ColorPhone.LoadDataFromXML(My.MySettings.Default.ColorPhoneXmlPath)

                End If


            End If



            If String.IsNullOrEmpty(res) Then
                'try another approach to find user
                Dim iexplore = From p In System.Diagnostics.Process.GetProcessesByName("iexplore") _
                            Select p.Handle

                If iexplore.Count = 0 Then
                    Dim explorer = From p In System.Diagnostics.Process.GetProcessesByName("explorer") _
                                           Select p.Handle
                    If explorer.Count = 0 Then

                        Dim firefox = From p In System.Diagnostics.Process.GetProcessesByName("firefox") _
                                          Select p.Handle
                        If firefox.Count = 0 Then
                            res = "unknown"

                        Else
                            res = ProcessHelper.GetCurrentProcessOwner(firefox.ToList(0))


                        End If


                    Else

                        res = ProcessHelper.GetCurrentProcessOwner(explorer.ToList(0))


                    End If




                Else 'interet

                    res = ProcessHelper.GetCurrentProcessOwner(iexplore.ToList(0))

                End If


            End If


            'Dim myDir = New DirectoryInfo(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData)) '.SystemDirectory.ToString()))

            'Dim dir = New System.IO.DirectoryInfo(myDir.Parent.FullName)

            'Dim myList = From folder In dir.Parent.GetDirectories()
            '             Where folder.Name <> "All Users"
            '             Order By folder.LastWriteTime Descending
            '             Select folder.Name


            'res = myList.First



        Catch ex As Exception

        End Try

        'res = res.Replace(".CS", "")

        'If mySplit.Length > 0 Then
        '    res = mySplit(0)
        'End If

        Return res


    End Function


End Class
